package BookMethods;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class AddMethod implements BookMethod{
    public void method(BookList bookList) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("输入书名");
        String nameOfBook = scanner.nextLine();

        System.out.println("输入作者");
        String author = scanner.nextLine();

        System.out.println("输入类型");
        String type = scanner.nextLine();

        System.out.println("输入价格");
        double price = scanner.nextDouble();

        Book book = new Book(nameOfBook, author, type, price, false);

        int currentSize = bookList.getUsedSize();//保存当前书架上有几本书

        if (currentSize == bookList.getBookList().length) {
            System.out.println("书架已满");
            return;
        }

        bookList.setBookList(currentSize++, book);

        bookList.setUsedSize(currentSize);

        System.out.println("添加成功");

    }
}
